import { Pipe, PipeTransform } from '@angular/core';
import { isTemplateExpression } from 'typescript';

/**
 * 会员成长值操作人
 * 'root':系统；'noRoot'：人工
 */
@Pipe({ name: 'growupStatus' })
export class growupStatusPipe implements PipeTransform {
  transform(value: string, exponent?: number): any {
    switch (value) {
      case 'root':
        return '系统'
      case 'noRoot':
        return '人工'
      default:
        return value || '-'
    }
  }
}

/**
 * 分值
 * 大于0 加号，绿色
 * 小于0 减号，红色
 * changeType 变更方式 1.增长 2.退减
 * exponent: text：文字内容，color：颜色
 */
@Pipe({ name: 'scoreStatus' })
export class scoreStatusPipe implements PipeTransform {
  transform(value: any, exponent?: any): any {
    if (exponent.type == 'color') {
      switch (exponent.changeType) {
        case 1:
          return '#008000'
        case 2:
          return '#f00000'
        default:
          return ''
      }
    } else if (exponent.type == 'text') {
      switch (exponent.changeType) {
        case 1:
          return '+' + value
        case 2:
          return (value && String(value).indexOf('-') != -1) ? value : '-' + value
        default:
          return '-'
      }
    }
  }
}

/************************** 账户流水 START *********************** */

/**
 * 审核状态:0 待审核 1.审核通过(已打款) 2.审核失败 3.待打款
 */
@Pipe({ name: 'examineStatus' })
export class ExamineStatePipe implements PipeTransform {
  transform(value: any, exponent?: any): any {
    switch (value) {
      case 0:
        return '待审核';
      case 1:
        return '审核通过(已打款)';
      case 2:
        return '审核不通过';
      case 3:
        return '待打款';
      default:
        return '-';
    }
  }
}

/**
 * 提现方式 1.支付宝 2.微信 3.银联
 */
@Pipe({ name: 'withdrawalWay' })
 export class WithdrawalWayPipe implements PipeTransform {
   transform(value: any, exponent?: any): any {
     switch (value) {
       case 1:
         return '支付宝';
       case 2:
         return '微信';
       case 3:
         return '银联';
       default:
         return '-';
     }
   }
 }

/**
 * 收支类型 定制分成、红包分成、爱乐物-推广分成、购买爱豆、订单退款、订单消费、游戏消费、兑换京东卡
 */
export const RevenueExpenditureArrs = [
  { id: 1, label: '定制分成', color: '#06B902' },
  { id: 2, label: '红包分成', color: '#06B902' },
  { id: 3, label: '爱乐物-推广分成', color: '#06B902' },
  { id: 4, label: '购买爱豆', color: '#06B902' },
  { id: 5, label: '订单退款', color: '#06B902' },
  { id: 6, label: '订单消费', color: '#F90000' },
  { id: 7, label: '游戏消费', color: '#F90000' },
  { id: 8, label: '兑换京东卡', color: '#F90000' },
  { id: 9, label: '人工调整', color: '#FF9933' },
];

@Pipe({ name: 'revenueExpenditure' })
export class RevenueExpenditurePipe implements PipeTransform {
  transform(value: any, type: any = 'text'): any {
    let tempObj = RevenueExpenditureArrs.find((item: any) => {
      return item.id == value;
    })
    
    if (type == 'text') {
      return tempObj?.label || '-';
    } else if (type == 'color') {
      return tempObj?.color || '';
    } else {
      return '';
    }
  }
}

/**
 * 收益审核状态 待审核、审核通过、审核不通过
 */
export const profitExamineArrs = [
  { id: 0, label: '待审核', color: '#FF9933' },
  { id: 1, label: '审核通过', color: '#06B902' },
  { id: 2, label: '审核不通过', color: '#F90000' }
];

@Pipe({ name: 'profitExamineStatus' })
export class ProfitExamineStatusPipe implements PipeTransform {
  transform(value: any, type: any = 'text'): any {
    let tempObj = profitExamineArrs.find((item: any) => {
      return item.id == value;
    })
    
    if (type == 'text') {
      return tempObj?.label || '-';
    } else if (type == 'color') {
      return tempObj?.color || '';
    } else {
      return '';
    }
  }
}

/**
 * 收益到账状态 未到账、已到账、已失效
 */
export const profitArrivalArrs = [
  { id: 0, label: '未到账', color: '#909399' },
  { id: 1, label: '已到账', color: '#06B902' },
  { id: 2, label: '已失效', color: '#F90000' },
];

@Pipe({ name: 'profitArrivalStatus' })
export class ProfitArrivalStatusPipe implements PipeTransform {
  transform(value: any, type: any = 'text'): any {
    let tempObj = profitArrivalArrs.find((item: any) => {
      return item.id == value;
    })
    
    if (type == 'text') {
      return tempObj?.label || '-';
    } else if (type == 'color') {
      return tempObj?.color || '';
    } else {
      return '';
    }
  }
}
/************************** 账户流水 END ************************* */

/************************* 爱豆充值 START ************************ */
/**
 * 审核状态:0 待审核 1.审核通过 2.审核失败 
 */
 export const idoAuditArrs = [
  { id: 0, label: '待审核', color: '#909399' },
  { id: 1, label: '审核通过', color: '#06B902' },
  { id: 2, label: '审核不通过', color: '#F90000' },
];

@Pipe({ name: 'idoAuditStatus' })
export class IdoAuditStatusPipe implements PipeTransform {
  transform(value: any, type: any = 'text'): any {
    let tempObj = idoAuditArrs.find((item: any) => {
      return item.id == value;
    })
    
    if (type == 'text') {
      return tempObj?.label || '-';
    } else if (type == 'color') {
      return tempObj?.color || '';
    } else {
      return '';
    }
  }
}
/************************** 爱豆充值 END ************************* */

// 验机分流水-收支类型：活动奖励、已失效、专业验机消费、购买验机分
export const machineScoreTypeArrs = [
  {value: 1, label: '购买验机分'},
  {value: 2, label: '专业验机消费'},
  {value: 3, label: '活动奖励'},
  {value: 4, label: '已失效'}
]
@Pipe({
  name: 'machineScoreTypes'
})
export class MachineScoreTypesPipe implements PipeTransform {
  transform(value: any) {
    let tempObj: any = machineScoreTypeArrs.find((item: any) => item.value === value);
    return tempObj?.label || '-';
  }
}
